﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TableJsonHelper
{
    /// <summary>
    /// XSL Add 2023 03 DataTable与json的互转，
    /// 对转换后或者输入的json进行加密，调用EncryptUitility库的EnOrDeEncryptHelper。
    /// </summary>
    public class DataTableAndJsonHelper
    {
        /// <summary>
        /// Datatable 转Json串
        /// </summary>
        /// <param name="table"></param>
        /// <returns></returns>
        static public string DataTableToJsonWithJsonNet(DataTable table)
        {
            string JsonString = string.Empty;
            JsonString = JsonConvert.SerializeObject(table);
            return JsonString;
        }
        /// <summary>
        /// JSon转DataTable。
        /// </summary>
        /// <param name="jsonContent"></param>
        /// <returns></returns>
        static public DataTable JsonToDataTableWithJsonNet(string jsonContent)
        {
            DataTable dt = (DataTable)JsonConvert.DeserializeObject(jsonContent, (typeof(DataTable)));
            return dt;
        }
    }
}
